package file;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Arrays;

public class FileDigui3 {

	public static void main(String[] args) throws IOException {
		/*
		 * File file = new File("D:" + File.separator + "test"); listAll(file);
		 */
		editFile();
	}

	public static void editFile() throws IOException {
		File file = new File("demo");
		if (!file.exists()) {
			file.mkdir();
		}
		File file2 = new File(file, "good.txt");
		if (!file2.exists()) {
			file2.createNewFile();
		}
		RandomAccessFile rac=new RandomAccessFile(file2, "rw");
		//System.out.println(rac.getFilePointer());
		rac.write("aaaaaaaaaaaaa".getBytes());
		//System.out.println(rac.getFilePointer());
		byte[] b=new byte[(int) rac.length()];
		rac.seek(0);
		rac.read(b);
		System.out.println(new String(b));
		
		rac.close();
	}

	/**
	 * 列出目录下的全部文件
	 * 
	 * @param file
	 */
	public static void listAll(File file) {
		File[] files = file.listFiles();
		if (files != null && files.length > 0) {
			for (File file2 : files) {
				if (file2.isFile()) {
					System.out.println(file2.getAbsolutePath());
				} else {
					listAll(file2);
				}
			}
		}
	}
}
